<?php
namespace app\admin\controller;
use app\admin\service\menu\Lists as RuinuoLists;
use app\admin\service\menu\Logic as RuinuoLogic;
use think\facade\Request;
use app\common\middleware\Auth;
use app\common\middleware\Power;
use app\common\middleware\Log;

class Menu
{
    protected $middleware = [Auth::class => [], Power::class => [], Log::class => []];
    /*列表模板及数据*/
    public function Index()
    {
        if (Request::isAjax() || Request::isPost()) {
            $RuinuoLists = new RuinuoLists();
            $data['rows'] =$RuinuoLists->Lists(input());//列表数据
            $data['total'] =$RuinuoLists->Total(input());//总数据
            return BackCode($data);
        }
        return ViewTpl('admin/menu/lists');
    }

    /*Tab及统计*/
    public function TabSum()
    {
        if (Request::isAjax() || Request::isPost()) {
            $RuinuoLists = new RuinuoLists();
            $data['tab'] =$RuinuoLists->Tab(input());//Tab统计
            $data['sum'] =$RuinuoLists->Sum(input());//Sum统计
            return BackCode($data);
        }
    }

    /*明细*/
    public function Detail()
    {
        if (Request::isAjax() || Request::isPost()) {
            $RuinuoLogic = new RuinuoLogic();
            $data=$RuinuoLogic->Detail(input());
            return BackCode($data['data'], $data['code'], $data['msg']);
        }
        return ViewTpl('admin/menu/form');
    }

    /*新增数据*/
    public function Add()
    {
        if (Request::isAjax() || Request::isPost()) {
            $RuinuoLogic = new RuinuoLogic();
            $data=$RuinuoLogic->Add(input());
            return BackCode($data['data'], $data['code'], $data['msg']);
        }
        return ViewTpl('admin/menu/form');
    }

    /*修改数据*/
    public function Edit()
    {
        if (Request::isAjax() || Request::isPost()) {
            $RuinuoLogic = new RuinuoLogic();
            $data=$RuinuoLogic->Edit(input());
            return BackCode($data['data'], $data['code'], $data['msg']);
        }
        return ViewTpl('admin/menu/form');
    }

    /*删除单条数据*/
    public function Delete()
    {
        if (Request::isAjax() || Request::isPost()) {
            $RuinuoLogic = new RuinuoLogic();
            $data= $RuinuoLogic->Delete(input('id'),1);
            return BackCode($data['data'], $data['code'], $data['msg']);
        }
    }

    /*批量删除数据*/
    public function batch_delete()
    {
        if (Request::isAjax() || Request::isPost()) {
            $RuinuoLogic = new RuinuoLogic();
            $data= $RuinuoLogic->Delete(input('ids'),2);
            return BackCode($data['data'], $data['code'], $data['msg']);
        }
    }

    /*单个字段修改*/
    public function update_field()
    {
        if (Request::isAjax() || Request::isPost()) {
            $RuinuoLogic = new RuinuoLogic();
            $data= $RuinuoLogic->UpdateField(input());
            return BackCode($data['data'], $data['code'], $data['msg']);
        }
    }

    /*导入Excel数据*/
    public function import_excel()
    {
        if (Request::isAjax() || Request::isPost()) {
            $file = Request::file("file") ? : Request::file("edit");
            $RuinuoLists = new RuinuoLists();
            $data=$RuinuoLists->InExcel($file);
            return BackCode($data['data'], $data['code'], $data['msg']);
        }
    }

    /*导出Excel数据*/
    public function export_excel()
    {
        $RuinuoLists = new RuinuoLists();
        $RuinuoLists->OutExcel(input());
    }

    /*下载Excel模板*/
    public function template_excel()
    {
        $RuinuoLists = new RuinuoLists();
        $RuinuoLists->TemplateExcel();
    }


}